﻿#include "crc32.h"
#include "ui_crc32.h"
#include "_def.h"
crc32::crc32(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::crc32)
{
    ui->setupUi(this);
    ui->lineEdit_head->setText(PROTOCOL_HEAD);
    ui->lineEdit_tail->setText(PROTOCOL_TAIL);
}

crc32::~crc32()
{
    delete ui;
}


void crc32::on_pushButton_cal_clicked()
{
    QString content = ui->textEdit_content->toPlainText();
    if(content.length()<=0)
        return;
    uint32_t length = content.length();
    ui->lineEdit_length->setText(QString::asprintf("%u",length));

    QByteArray result;
    result = ui->lineEdit_head->text().toLocal8Bit();
    result.append('\0');
    result.append(ui->lineEdit_length->text());
    result.append('\0');
    result.append(ui->textEdit_content->toPlainText());
    result.append('\0');
    uint32_t crc = GetCRC32(result);
    ui->lineEdit_crc32->setText(QString::asprintf("%02x",crc));
    result.append(ui->lineEdit_crc32->text());
    result.append('\0');
    result.append(ui->lineEdit_tail->text());
    result.append('\0');
}
